local ClientOHOH = _G.ClientOHOH;

local M = ClientOHOH.class.new(script, ClientOHOH.files.BaseObject());

local TweenHelper = _G.CommonOHOH.load.TweenHelper();
local CellClass=require(script.Parent.Parent.WeaopnEquipGui.Cell)

function M.new(...)
	return M(...);
end;

function M.ctor(self,root,cell,ctrl)
    self.ctrl=ctrl
    self.cellPerfab=cell
    self.root=root
    self.layout=root:FindFirstChildOfClass("UIGridLayout")
    self.List={}
	M.super.ctor(self);
end;

function M.dtor(self)
	M.super.dtor(self);
end;

-- 根据数据创建项
function M.AddCell(self,ui,data)

    local cell=CellClass.new(ui,data,self.ctrl)
    data.RemoveEvent:Connect(function()
        cell:dtor()
        self.List[data.id]=nil
    end)

    cell.click:Connect(function()
        self.ctrl:CellClick(cell)
    end)

    self.List[data.id]=cell

    if self.FilterCell and not self.FilterCell:IsEqual(cell) then
        cell:Hide()
    end
end


function M.IshadData(self,data)
    if self.List[data.id] then
        return true
    end
    return false
end

function M.FilterByCell(self,cell)

    if cell then
        self.FilterCell=cell
        for k,v in pairs(self.List) do
            if  v:IsEqual(cell) then
                 v:Show()
            else
                 v:Hide()
            end
         end
    else
        self.FilterCell=nil
        for k,v in pairs(self.List) do
            v:Show()
         end
    end

end

function M.FindCellByCidAndLevel(self,cid,level)
    for k,v in pairs(self.List) do
            local data=v:GetData()
            if data.cfgId==cid and data.level==level  then
                return v
            end
     end
end

return M